<?php

declare(strict_types=1);

namespace App\Controller\Callback;
use App\Controller\AbstractController;
use Hyperf\HttpServer\Annotation\AutoController;
use App\Model\PayLog;
use App\JsonRpc\impl\PayLogService;

/**
 * @AutoController(prefix="/callback/pay")
 */
class Pay extends AbstractController
{
    public function demo() {
        $this->validate([
            'order_no' => 'required',
            'transaction_id' => 'required',
            'total_price' => 'required',
        ]);
        $params = $this->request->all();
        $exist = PayLog::query()->where('order_no', $params['order_no'])->first();
        if ($exist != null) {
            return $this->error('exist');
        }

        $paylog = new PayLog();
        $paylog->order_no = $params['order_no'];
        $paylog->transaction_id = $params['transaction_id'];
        $paylog->total_price = $params['total_price'];

        $paylog->save();

        return $this->success($paylog);
    }
}
